using System.Collections.Generic;

namespace LuceneSearch.ContactApp.Indexing
{
    public class EntityIndexUpdater : IEntityIndexProcessor
    {
        private readonly EntityIndexRemover entityIndexRemover;
        private readonly EntityIndexWriter entityIndexWriter;

        public EntityIndexUpdater(EntityIndexRemover entityIndexRemover, EntityIndexWriter entityIndexWriter)
        {
            this.entityIndexRemover = entityIndexRemover;
            this.entityIndexWriter = entityIndexWriter;
        }

        public bool CanProcess(IndexWorkType indexWorkType)
        {
            return indexWorkType == IndexWorkType.Update;
        }

        public void Process(IEnumerable<object> entities)
        {
            entityIndexRemover.Process(entities);
            entityIndexWriter.Process(entities);
        }
    }
}